import request from '@/utils/request';
import type { BasicMsg, BasicMsgWithData, Dish } from '@/types';

// 获取所有菜品
export const getAllDishes = (): Promise<BasicMsgWithData<Dish[]>> => {
  return request({
    url: '/api/dishes',
    method: 'get'
  });
};

// 根据ID获取菜品
export const getDishById = (id: number): Promise<BasicMsgWithData<Dish>> => {
  return request({
    url: `/api/dishes/${id}`,
    method: 'get'
  });
};

// 创建菜品
export const createDish = (data: Dish): Promise<BasicMsg> => {
  return request({
    url: '/api/dishes',
    method: 'post',
    data
  });
};

// 更新菜品
export const updateDish = (id: number, data: Dish): Promise<BasicMsg> => {
  return request({
    url: `/api/dishes/${id}`,
    method: 'put',
    data
  });
};

// 删除菜品
export const deleteDish = (id: number): Promise<BasicMsg> => {
  return request({
    url: `/api/dishes/${id}`,
    method: 'delete'
  });
};

// 根据菜品类型查询
export const getDishesByType = (type: string): Promise<BasicMsgWithData<Dish[]>> => {
  return request({
    url: `/api/dishes/type/${encodeURIComponent(type)}`,
    method: 'get'
  });
};

// 根据菜品名称模糊查询
export const getDishesByName = (name: string): Promise<BasicMsgWithData<Dish[]>> => {
  return request({
    url: `/api/dishes/name/${encodeURIComponent(name)}`,
    method: 'get'
  });
};

// 获取正常销售的菜品
export const getAvailableDishes = (): Promise<BasicMsgWithData<Dish[]>> => {
  return request({
    url: '/api/dishes/available',
    method: 'get'
  });
};

